<template>
  <div>
    <van-popup
      v-model="visible"
      position="bottom"
      :style="{ height: 'auto' }"
      @close="handleCancel">
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <div style="margin-top:10px;width:100%;">
            <a-form-item label="客户名称">
              <a-input placeholder="请输入客户名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </div>
          <a-row>
            <a-col :span="24">
              <div style="margin-bottom:5px;">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                <a-button type="primary" @click="handleOk" style="margin-left: 8px">确定</a-button>
              </div>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <div>
        <van-radio-group v-model="radio" class="list">
          <van-list
            v-model="loading"
            :finished="finished"
            offset="30"
            finished-text="没有更多了"
            @load="downLoadData"
            :immediate-check="false">
            <van-radio
              style="padding: 0 20px;"
              v-for="(item,i) in dataSource"
              :key="i"
              :name="i">
              <div class="userItem">
                <span style="width:20%;">{{ item.name }}</span>
                <span style="width:40%;">{{ item.phone }}</span>
                <!--<span style="width:40%;">{{ item.username }}</span>-->
              </div>
            </van-radio>
          </van-list>
        </van-radio-group>
      </div>
    </van-popup>
  </div>

  <!--<a-modal
    :title="title"
    :width="800"
    :visible="visible"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    &lt;!&ndash; 查询区域 &ndash;&gt;
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :span="8">
            <a-form-item label="客户姓名">
              <a-input placeholder="请输入客户姓名" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
                    <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                      <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                      <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                    </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    &lt;!&ndash; table区域-begin &ndash;&gt;
    <div>
      <a-table
        size="small"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :scroll="{ y: 240 }"
        :rowSelection="{selectedRowKeys: selectedRowKeys,onSelectAll:onSelectAll,onSelect:onSelect,onChange: onSelectChange,type:'radio'}"
        @change="handleTableChange">

      </a-table>
    </div>
    &lt;!&ndash; table区域-end &ndash;&gt;

  </a-modal>-->
</template>

<script>

  import {getAction} from '@/api/manage'
  import '@/assets/less/TableExpand.less'
  import {mixinDevice} from '@/utils/mixin'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'

  export default {
    name: "chooseCustomerModal",
    mixins: [JeecgListMixin, mixinDevice],
    data() {
      return {
        title: "",
        names: [],
        visible: false,
        placement: 'right',
        description: '',
        // 查询条件
        queryParam: {},
        //职务条件
        post:'',
        labelCol: {
          xs: {span: 24},
          sm: {span: 5},
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 16},
        },
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 50,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '客户姓名',
            align: "center",
            width: 100,
            dataIndex: 'name'
          },
          {
            title: '电话',
            align: "center",
            width: 100,
            dataIndex: 'phone'
          },
          {
            title: '地址',
            align: "center",
            width: 100,
            dataIndex: 'address'
          },
        ],
        //数据集
        dataSource: [],
        //工种数据
        kindOfWorkData:[],
        loading: false,
        selectedRowKeys: [],
        selectedRows: [],
        url: {
          list: "/ghCustomerInfo/list",
        },
        radio: '',
        finished:false,
      }
    },
    created() {
      this.loadData();
    },
    methods: {
      filterOptionKindOfWork(input, option) {
        return (
          option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        );
      },
      changeKindOfWork(value){
        this.loadData(1);
      },
      searchQuery() {
        this.loadData(1);
      },
      searchReset() {
        this.queryParam = {};
        this.loadData(1);
      },
      handleCancel() {
        this.visible = false;
        this.onClearSelected();
      },
      handleOk() {
        if (this.radio === ''){
          this.$message.warning("请选择一个用户")
          return;
        }
        this.selectedRows = [
          this.dataSource[this.radio]
        ]
        this.$emit("selectFinished", this.selectedRows[0]);
        this.visible = false;
      },
      add() {
        this.visible = true;
        this.loadData();
      },
      downLoadData(){
        this.ipagination.current++;
        this.finished = false
        this.loadData()
      },
      loadData(arg) {
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
          this.dataSource = []
        }
        var params = this.getQueryParams();//查询条件
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = [...this.dataSource, ...res.result.records];
            if(res.result.total)
            {
              this.ipagination.total = res.result.total;
            }else{
              this.ipagination.total = 0;
            }
            this.loading = false;
            if(res.result.records.length<10){
              this.finished = true;
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          }else{
            this.$message.warning(res.message)
          }
        })
      },
      onSelectAll(selected, selectedRows, changeRows) {

      },
      onSelect(record, selected) {

      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectionRows
      },

    }
  }
</script>

<style scoped lang="less">
  .list{
    overflow-y: scroll;
    height:380px;
    .userItem{
      display:flex;
      justify-content:space-between;
      height: 40px;
      line-height: 40px;
      border-top: 1px solid #f6f6f6;
      span{
        text-align:left;
      }
    }
  }
  .list /deep/ .van-radio__label{
    width:calc(100% - 30px);
  }
  ::-webkit-scrollbar {
    display: none;
  }
  .table-page-search-wrapper{
    padding: 0 20px;
  }
  .ant-card-body .table-operator {
    margin-bottom: 18px;
  }

  .ant-table-tbody .ant-table-row td {
    padding-top: 15px;
    padding-bottom: 15px;
  }

  .anty-row-operator button {
    margin: 0 5px
  }

  .ant-btn-danger {
    background-color: #ffffff
  }

  .ant-modal-cust-warp {
    height: 100%
  }

  .ant-modal-cust-warp .ant-modal-body {
    height: calc(100% - 110px) !important;
    overflow-y: auto
  }

  .ant-modal-cust-warp .ant-modal-content {
    height: 90% !important;
    overflow-y: hidden
  }
  .ant-form-item{
    margin-bottom:10px !important;
  }
  .table-page-search-submitButtons{
    margin-bottom:10px !important;
  }
</style>